package com.lkd.http.controller;

import com.lkd.entity.NodeEntity;
import com.lkd.http.controller.vo.NodeReq;
import com.lkd.service.NodeService;
import com.lkd.vo.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
public class NodeController {

    @Autowired
    private NodeService nodeService;

    /**
     * 分页查询
     * @param pageIndex
     * @param pageSize
     * @param name
     * @param regionId
     * @return
     */
    @GetMapping("/node/search")
    public Pager<NodeEntity> search(@RequestParam(name = "pageIndex",required = false,defaultValue = "1")Long pageIndex,
                                    @RequestParam(name = "pageSize",required = false,defaultValue = "10")Long pageSize,
                                    @RequestParam(name = "name",required = false)String name,
                                    @RequestParam(name = "regionId",required = false) Long  regionId){
        return nodeService.search(pageIndex,pageSize,name,regionId);
    }

    /**
     * 新增
     * @param nodeReq
     * @return
     */
    @PostMapping("/node")
    public Boolean saveNode(@Valid @RequestBody NodeReq nodeReq){
        return nodeService.saveNode(nodeReq);
    }

    /**
     * 修改
     * @param nodeReq
     * @return
     */
    @PutMapping("/node/{id}")
    public Boolean updateNode(@Valid @RequestBody NodeReq nodeReq,
                            @PathVariable(name = "id")Long nodeId){
        return nodeService.updateNode(nodeReq,nodeId);
    }

    /**
     * 删除
     * @param nodeId
     * @return
     */
    @DeleteMapping("/node/{id}")
    public Boolean delNode(@PathVariable(name = "id")Long nodeId){
        return nodeService.del(nodeId);
    }
}
